//
//  ZSLMainTabBarController.swift
//  micro_blog
//
//  Created by Mac on 16/9/19.
//  Copyright © 2016年 Mac. All rights reserved.
//

import UIKit

class ZSLMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tab = ZSLTabBar()
        
        tab.newDelegate = self
        
        tab.composeBtnClosure = { [weak self] in

            print("我是闭包调过来的")
            
        }
        
       setValue(tab, forKey: "tabBar")
        
        //添加子视图
        addChildViewController(childController: ZSLHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(childController: ZSLMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        
        addChildViewController(childController: ZSLDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(childController: ZSLProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
        
    }
    
     func addChildViewController(childController: UIViewController , title: String,imageName: String)
    {
        childController.tabBarItem.image = UIImage(named: imageName)
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.withRenderingMode(.alwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 14)], for: .normal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: .selected)
        
        //合成一句的代码显示标题
        childController.title = title
        
        let nav = ZSLNavigationController(rootViewController: childController)
        
        addChildViewController(nav)
        
        
    }

   
}

extension ZSLMainTabBarController: ZSLTabBarDelegate {
    
    func didSelectedComposeButton() {
        
        print("代理的调用")
    }
}
